package com.ynny.controller;

import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PathVariableTestController {

    // 普通的路径变量写法
    @GetMapping("/testPathVariable01")
    @ResponseBody
    public String testPathVariable01(HttpServletRequest request){

        String id = request.getParameter("id");
        System.out.println(id);

        return "testPathVariable01";
    }

    // 使用@PathVariable注解
    // 路径 占位符 方式
    @GetMapping("/testPathVariable02/{id}/{name}")
    @ResponseBody
    public String testPathVariable02(@PathVariable(name = "id") Integer id,
                                     @PathVariable(name = "name") String name){

        System.out.println(id);
        System.out.println(name);

        return "testPathVariable02";

    }


}
